package thread_pool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/23
 * Time:9:49
 * 重命名线程名
 **/
public class PoolDemo13 {
    public static void main(String[] args) {

        ThreadFactory threadFactory = new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setName("myThreadPool-");
                return t;
            }
        };
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                5,5,0,
                TimeUnit.SECONDS,new LinkedBlockingQueue<>(1000),
                threadFactory);

        for (int i = 0; i < 5; i++) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程名称"+Thread.currentThread().getName());
                }
            });
        }
    }
}
